package com.wdc.deliveryrobot.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdc.deliveryrobot.R;
import com.wdc.deliveryrobot.event.Event;
import com.wdc.deliveryrobot.fragment.BaseFragment;
import com.wdc.deliveryrobot.fragment.DeliveryFragment;
import com.wdc.deliveryrobot.fragment.MapFragment;
import com.wdc.deliveryrobot.fragment.VersionSettingFragment;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class SettingActivity extends BaseActivity implements View.OnClickListener {

    private FrameLayout frameLayoutContain;

    private TextView textViewOne,textViewTwo,textViewThree,textView;

    private LinearLayout linearLayout,linearLayoutOne,linearLayoutTwo,linearLayoutThree,linearLayoutMain;

    private ImageButton imageButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        frameLayoutContain = findViewById(R.id.settingContain);


        textViewOne = findViewById(R.id.setting_one);
        textViewTwo = findViewById(R.id.setting_two);
        textViewThree = findViewById(R.id.setting_three);
        imageButton = findViewById(R.id.return_back);
        linearLayoutOne = findViewById(R.id.layout_one);
        linearLayoutTwo = findViewById(R.id.layout_two);
        linearLayoutThree = findViewById(R.id.layout_three);
        linearLayoutMain = findViewById(R.id.settingList);
        linearLayout = linearLayoutOne;
        //选中状态
        linearLayout.setBackgroundResource(R.drawable.select_button);
        textViewOne.setOnClickListener(this);
        textViewTwo.setOnClickListener(this);
        textViewThree.setOnClickListener(this);
        imageButton.setOnClickListener(this);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.settingContain, new BaseFragment())
                    .commit();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.setting_one:
                if (linearLayout != linearLayoutOne){
                    linearLayout.setBackgroundResource(R.drawable.noselect_button);
                    linearLayout = linearLayoutOne;
                    linearLayout.setBackgroundResource(R.drawable.select_button);
                    changeFragment(new BaseFragment());
                }
                break;
            case R.id.setting_two:
                if (linearLayout != linearLayoutTwo){
                    linearLayout.setBackgroundResource(R.drawable.noselect_button);
                    linearLayout = linearLayoutTwo;

                    linearLayout.setBackgroundResource(R.drawable.select_button);
                    changeFragment(new MapFragment());
                }
                break;
            case R.id.setting_three:
                if (linearLayout != linearLayoutThree){
                    linearLayout.setBackgroundResource(R.drawable.noselect_button);
                    linearLayout = linearLayoutThree;
                    linearLayout.setBackgroundResource(R.drawable.select_button);
//                    Log.d("thd_","数据:" + selfChassisState.getRobtId() + " " + selfChassisState.getVersion() + " " + selfChassisState.getCurrentActionID());
//                    VersionSettingFragment versionSettingFragment = new VersionSettingFragment();
//                    changeFragment(versionSettingFragment);
//                    versionSettingFragment.setData(selfChassisState.getRobtId() == null ? " " : selfChassisState.getRobtId());
                    changeFragment(new VersionSettingFragment());
                }
                break;
            case R.id.return_back:
                finish();
                break;
        }
    }

    public void changeFragment(Fragment newFragment) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.settingContain, newFragment)
                .addToBackStack(null) // 可选：将此事务添加到回退栈
                .commit();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void OnDataEvent(Event.OnDataEvent onDataEvent){

    }
}